package com.it.selfAfter.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsAutoIncrement;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsKey;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;

import javax.annotation.PreDestroy;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
import java.util.Date;

@Data
@TableName ("sys_users")
@AllArgsConstructor
@Table(name = "sys_users", comment = "用户表")//设置表名  注释
public class Users {

  private static final long serialVersionUID = 9435278593475930L;
  
  @IsAutoIncrement   //自增
  @IsKey             //主键
  @Id
  @TableId( value = "id", type = IdType.AUTO)
  @Column(name = "id", comment = "用户ID")//字段注释
  private Long id;

  /**
   * 用户名
   */
  @Column(name = "username",comment = "用户名", length = 255)
  private String username;

  /**
   * 密码
   */
  @Column(name = "password",comment = "密码", length = 255)
  private String password;

  /**
   * 联系邮箱
   */
  @Column(name = "email",comment = "联系邮箱", length = 255)
  private String email;

  /**
   * 联系手机
   */
  @Column(name = "mobile",comment = "联系手机", length = 255)
  private String mobile;
  /**
   * 姓名
   */
  @Column(name = "name", comment = "姓名", length = 255)
  private String name;

  /**
   * 密码盐
   */
 
  @Column(name = "salt",comment = "密码盐", length = 255)
  private String salt;


  /**
   * 最后修改密码时间
   */

  @Column(name = "pwd_update_time", type = MySqlTypeConstant.TIMESTAMP, comment = "最后修改密码时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
  private Date pwd_update_time;
  
  
  /**
   * 最后登录时间
   */
  @Column(name = "last_login_time", type = MySqlTypeConstant.TIMESTAMP, comment = "最后登录时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
  private Date last_login_time;

  /**
   * 创建时间
   */
  
  @Column(name = "create_time", type = MySqlTypeConstant.TIMESTAMP, comment = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
  private Date create_time;

  /**
   * 删除时间
   */
  
  @Column(name = "delete_time", type = MySqlTypeConstant.TIMESTAMP, comment = "删除时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
  private Date delete_time;

  /**
   * 是否删除
   */
  @Column(name = "is_deleted", comment = "是否删除 0、正常 1、删除",defaultValue = "0", length = 10)
  private Integer is_deleted;

  /**
   * 状态 0、正常 1、锁定
   */
  @Column(name = "is_admin", comment = "状态 0、正常 1、锁定",defaultValue = "0", length = 10)
  private Integer is_admin;

  /**
   * 是否为超级管理员
   */
  @Column(name = "is_super_admin", comment = "是否为超级管理员 0、正常 1、删除",defaultValue = "0", length = 10)
  private Integer is_super_admin;


  /**
   * 登录用户名
   */
  @Column(name = "today_saying")
  private String today_saying;

  /**
   * 用户头像
   */
  @Column(name = "images")
  private String images;

  /**
   * 用户id/Token
   */
  @Column(name = "uuid")
  private String uuid;
  
  /**
   * 用户id
   */
  @Column(name = "user_id")
  private String user_id;

  public Users(String username, String password, String email, String mobile, String name,
               String salt, Date pwdUpdateTime, Date lastLoginTime, Date createTime,
               Date deleteTime, Integer isDeleted, Integer isAdmin, Integer isSuperAdmin,
               String todaySaying, String images, String uuid, String user_id) {
    this.username = username;
    this.password = password;
    this.email = email;
    this.mobile = mobile;
    this.name = name;
    this.salt = salt;
    this.pwd_update_time = pwdUpdateTime;
    this.last_login_time = lastLoginTime;
    this.create_time = createTime;
    this.is_deleted = isDeleted;
    this.is_admin = isAdmin;
    this.is_super_admin = isSuperAdmin;
    this.today_saying = todaySaying;
    this.images = images;
    this.uuid = uuid;
    this.user_id = user_id;
  }
  
  public Users () {
  
  }
  
  /**
   * 新增数据时自动添加时间
   */
  @PrePersist
  protected void onCreate() {
    create_time = new Date();
  }
  
  /**
   * 更新数据时自动更新时间
   */
  @PreUpdate
  protected void onUpdate() {
    pwd_update_time = new Date();
  }
  
  /**
   * 删除数据时自动更新时间
   */
  @PreRemove
  protected void onDelete() {
    is_deleted = 1;
  }
  
  /**
   * 登录时自动更新时间
   */
  @PreUpdate
  protected void onLogin() {
    last_login_time = new Date();
  }
}
